<?php

namespace frontend\controllers;

use common\models\Country;
use yii\data\Pagination;
use yii\web\Controller;

class CountryController extends Controller
{

    public function actionIndex()
    {
//        $data = Country::find()->orderBy('name')->asArray()->all();

//        $one = Country::findOne('US')->toArray();
        $one_object = Country::findOne('US');
        $one_object->name = 'qu ni daye de';
        dd($one_object->save());

//        dd($one_object->name);
//        dd($one_object);
    }



    public function actionSearch()
    {
        $query = Country::find();

        $pagination = new Pagination([
            'defaultPageSize' => 5,
            'totalCount' => $query->count(),
        ]);

        $countries = $query->orderBy('name')
            ->offset($pagination->offset)
            ->limit($pagination->limit)
            ->all();

        return $this->render('index', [
            'countries' => $countries,
            'pagination' => $pagination,
        ]);
    }



    public function actionPage()
    {
        $query = Country::find();

        $pagination = new Pagination([
            'defaultPageSize' => 10,
            'totalCount' => $query->count,
        ]);

        $countries = $query->orderBy('name')
            ->offset($pagination->offset)
            ->limit($pagination->limit)
            ->all();

        return $this->render('index', [

        ]);

    }











}